<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
defined('_JEXEC') or die;

jimport('joomla.application.component.modeladmin');

class CprojectModelSection extends JModelAdmin {

    public function getTable($name = 'Section', $prefix = 'Table', $options = array()) {
        $model = parent::getTable($name, $prefix, $options);
        return $model;
    }

    function getForm($data = array(), $loadData = true) {
        $form = $this->loadForm('com_cproject.section', 'section', array('control' => 'jform', 'load_data' => $loadData));
        if (empty($form)) {
            return false;
        }

        return $form;
    }

    function loadFormData() {

        $data = JFactory::getApplication()->getUserState('com_cproject.edit.section.data', array());

        if (empty($data)) {
            $data = $this->getItem();
        }
        return $data;
    }

    public function save($data) {
        JRequest::checkToken() or die('Invalid Token');
        $user = & JFactory::getUser();
        $cid = JRequest::getVar('cid', array(0), 'post', 'array');
        $data['id'] = (int) $cid[0];

        if (!$data['id']) {
            $data['created_by'] = $user->get('id');
            $data['created_on'] = gmdate('Y-m-d H:i:s');
        }
        $data['modified_by'] = $user->get('id');
        $data['modified_on'] = gmdate('Y-m-d H:i:s');
        $data['alias'] = CprojectHelper::alias($data['name']);
        if (parent::save($data)) {

            return true;
        }


        return false;
    }

}

?>
